package com.sojson.service.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sojson.dao.AdDao;
import com.sojson.dao.AdPositionDao;
import com.sojson.entity.po.Ad;
import com.sojson.entity.po.AdPosition;
import com.sojson.service.AdPositionService;

/**
 * 广告位管理表Service实现类
 * 
 * @author liu
 * @date 2021-03-16
 */
@Service
public class AdPositionServiceImpl implements AdPositionService {

    @Resource
    private AdPositionDao adPositionDaoImpl;
    @Resource
    private AdDao adDaoImpl;

    /**
     * 单条插入
     * 
     * @param adPosition
     * @return
     * @throws SQLException
     */
    @Override
    public int insert(AdPosition adPosition) {
        int insert = adPositionDaoImpl.insert(adPosition);
        return insert;
    }

    /**
     * 批量插入
     * 
     * @param adPosition
     * @return
     * @throws SQLException
     */
    @Override
    public int insertList(AdPosition adPosition) {
        int insertList = adPositionDaoImpl.insertList(adPosition.getAdPositions());
        return insertList;
    }

    /**
     * 通过对象批量删除(物理删除)
     * 
     * @param adPosition
     * @return
     * @throws SQLException
     */
    @Override
    public int deleteByDto(AdPosition adPosition) {
        int deleteByDto = adPositionDaoImpl.deleteByDto(adPosition);
        return deleteByDto;
    }

    /**
     * 统计全部数量
     * 
     * @return
     * @throws SQLException
     */
    @Override
    public int countAll() {
        int countAll = adPositionDaoImpl.countAll();
        return countAll;
    }

    /**
     * 查询所有
     * 
     * @return
     * @throws SQLException
     */
    @Override
    public List<AdPosition> findAll() {
        List<AdPosition> findAll = adPositionDaoImpl.listAll();
        return findAll;
    }

    /**
     * 根据对象统计数量
     * 
     * @param adPosition
     * @return
     * @throws SQLException
     */
    @Override
    public int countByDto(AdPosition adPosition) {
        int countByDto = adPositionDaoImpl.countByDto(adPosition);
        return countByDto;
    }

    /**
     * 根据对象查询
     * 
     * @param adPosition
     * @return
     * @throws SQLException
     */
    @Override
    public List<AdPosition> findByDto(AdPosition adPosition) {
        List<AdPosition> findByDto = adPositionDaoImpl.listByDto(adPosition);
        return findByDto;
    }

    /**
     * 通过id删除(物理删除)
     * 
     * @param id
     * @return
     * @throws SQLException
     */
    @Override
    @Transactional
    public int deleteById(Integer id) {
        Ad ad = new Ad();
        ad.setPositionId(id);
        adDaoImpl.deleteByDto(ad);
        int deleteById = adPositionDaoImpl.deleteById(id);
        return deleteById;
    }

    /**
     * 通过id列表删除(物理删除)
     * 
     * @param ids
     * @return
     * @throws SQLException
     */
    @Override
    public int deleteByIdList(ArrayList<Integer> ids) {
        int deleteByIdList = adPositionDaoImpl.deleteByIdList(ids);
        return deleteByIdList;
    }

    /**
     * 通过id更新(全部更新)
     * 
     * @param adPosition
     * @return
     * @throws SQLException
     */
    @Override
    public int updateById(AdPosition adPosition) {
        int updateById = adPositionDaoImpl.updateById(adPosition);
        return updateById;
    }

    /**
     * 通过id列表更新(全部更新)(更新内容相同)
     * 
     * @param adPosition
     * @return
     * @throws SQLException
     */
    @Override
    public int updateStaticByIdList(AdPosition adPosition) {
        int updateStaticByIdList = adPositionDaoImpl.updateStaticByIdList(adPosition);
        return updateStaticByIdList;
    }

    /**
     * 通过id列表更新(全部更新)(更新内容不相同)
     * 
     * @param adPosition
     * @return
     * @throws SQLException
     */
    @Override
    public int updateChangeByIdList(AdPosition adPosition) {
        int updateChangeByIdList = adPositionDaoImpl.updateChangeByIdList(adPosition.getAdPositions());
        return updateChangeByIdList;
    }

    /**
     * 通过id更新(局部更新)
     * 
     * @param adPosition
     * @return
     * @throws SQLException
     */
    @Override
    public int updatePartialById(AdPosition adPosition) {
        int updatePartialById = adPositionDaoImpl.updatePartialById(adPosition);
        return updatePartialById;
    }

    /**
     * 通过id列表更新(局部更新)(更新内容相同)
     * 
     * @param adPosition
     * @return
     * @throws SQLException
     */
    @Override
    public int updateStaticPartialByIdList(AdPosition adPosition) {
        int updateStaticPartialByIdList = adPositionDaoImpl.updateStaticPartialByIdList(adPosition);
        return updateStaticPartialByIdList;
    }

    /**
     * 通过id列表更新(局部更新)(更新内容不相同)
     * 
     * @param adPosition
     * @return
     * @throws SQLException
     */
    @Override
    public int updateChangePartialByIdList(AdPosition adPosition) {
        int updateChangePartialByIdList = adPositionDaoImpl.updateChangePartialByIdList(adPosition.getAdPositions());
        return updateChangePartialByIdList;
    }

    /**
     * 通过id查询
     * 
     * @param id
     * @return
     * @throws SQLException
     */
    @Override
    public AdPosition findById(Integer id) {
        AdPosition findById = adPositionDaoImpl.findById(id);
        return findById;
    }

    /**
     * 通过id列表查询
     * 
     * @param ids
     * @return
     * @throws SQLException
     */
    @Override
    public ArrayList<AdPosition> findByIdList(ArrayList<Integer> ids) {
        ArrayList<AdPosition> findByIdList = adPositionDaoImpl.findByIdList(ids);
        return findByIdList;
    }

    /**
     * 通过对象查询id列表
     * 
     * @param adPosition
     * @return
     * @throws SQLException
     */
    @Override
    public ArrayList<Integer> findIdByDto(AdPosition adPosition) {
        ArrayList<Integer> findIdByDto = adPositionDaoImpl.findIdByDto(adPosition);
        return findIdByDto;
    }

    /**
     * 清空数据(物理清空)
     * 
     * @throws SQLException
     */
    @Override
    public void clear() {
        adPositionDaoImpl.clear();
    }

}